/*
*/
#ifndef _IIC_H
#define _IIC_H

#include "Include.h"

#include "intrinsics.h"     //__no_operation

     

/*IIC baudrate defination*/
#define IIC_BAUD_100K        0x00    //baudrate 100Kbps
#define IIC_BAUD_400K        0x01    //baudrate 400Kbps

/*IIC endian defination*/
#define ENDIAN_LSB  BIT4
#define ENDIAN_MSB  0x00
#define IIC_ENDIAN		    ENDIAN_MSB 	//IIC endian setting

/*SICFG*/
#define IIC_TXS		        BIT3    //enable transmitting start bit
#define IIC_TXP		        BIT1    //enable transmitting stop bit
#define IIC_TXD		        BIT2    //enable transmitting 8 bit data byte
#define IIC_TXRS		    0x03    //enable transmitting restart bit

#define IIC_BUSY            BIT1    /*the interface is receiving or transmitting                              data*/
#define IIC_ACK             BIT0    //enable transmitting ACK bit
     
/*ACK*/
#define IIC_WACK	0x00            //with ACK
#define IIC_NACK	0x01            //without ACK

 uint8 IIC_Init(uint8 mcu_frq, uint8 baud);                 //initialization
 uint8 IIC_RD_B(uint32 rd_addr, uint8 *rd_buff);            //read one byte
 uint8 IIC_RD_P(uint32 rd_addr, uint8 *rd_buff, uint32 rd_len);//read page
 uint8 IIC_WR_B(uint32 wr_addr, uint8 wr_buff);             //write one byte
 uint8 IIC_WR_P(uint32 wr_addr, uint8 *wr_buff, uint32 wr_len);//write page

 /*IIC bottom functions*/
void IIC_GPIO_Init(void);                //configure I/O ports
void IIC_Set_Period(uint16 val);           //configure timer divider threshold
uint8 IIC_Start(void);                     //transmit start bit
uint8 IIC_ReStart(void);                   //transmit restart bit
uint8 IIC_Stop(void);                      //transmit stop bit
uint8 IIC_Wait_Busy(void);                 //check busy state
uint8 IIC_Wait_Ack(void);                  //check ACK
uint8 IIC_Send_Data(uint8 txd);               //transmit 8-bit data byte
uint8 IIC_Read_Data(uint8 *rd_val, uint8 ack);   //receive 8-bit data byte


#endif 